<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 后台用户授权
 */
class CreateAdminsAuthorization extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('role', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',100)->unique()->comment('角色的唯一名称');
            $table->string('displayName')->nullable()->comment('人类可读的角色名，例如“后台管理员”、“作者”、“雇主”等');
            $table->string('description')->nullable()->comment('该角色的详细描述');
            $table->timestamps();
        });

        Schema::create('role_admin', function (Blueprint $table) {
            $table->integer('role_id');
            $table->integer('admin_id');
        });

        Schema::create('permission', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',100)->unique()->comment('权限的唯一名称，如“create/post”，“edit/post”等');
            $table->string('displayName')->nullable()->comment('人类可读的权限名称，如“发布文章”，“编辑文章”等');
            $table->integer('root_pid')->comment('根节点主键ID');
            $table->integer('pid')->comment('父类主键ID');
            $table->integer('lft')->comment('左值');
            $table->integer('rgt')->comment('右值');
            $table->tinyInteger('level')->comment('级别,深度');
            $table->timestamps();
        });

        Schema::create('role_permission', function (Blueprint $table) {
            $table->integer('role_id');
            $table->integer('permission_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('permission');
        Schema::dropIfExists('role');
        Schema::dropIfExists('role_admin');
        Schema::dropIfExists('role_permission');
    }
}
